home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_clone.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  8KB  |  328 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_CLONING    /* Support code */
  17.  
  18. VOID
  19. LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
  20. {
  21.     struct ColorSpec    *ColourSpec;
  22.     struct ColourRecord    *ColourRecord;
  23.     struct CloneExtra    *Extra;
  24.     LONG                 AllocationSize = 0;    /* For the sake of the compiler, make sure this is initialized */
  25.     LONG                 i,j,NumColours;
  26.     UWORD                *Pens;
  27.     struct Screen        *Screen;
  28.     ULONG                 DisplayID;
  29.     UWORD                 EndPen;
  30.  
  31.     ColourSpec        = NULL;
  32.     ColourRecord    = NULL;
  33.     Extra            = Handle->CloneExtra;
  34.     Pens            = Handle->CloneExtra->ScreenPens;
  35.     DisplayID        = GetVPModeID(&Handle->Screen->ViewPort);
  36.     EndPen            = (UWORD)~0;
  37.  
  38.     if(Handle->ExactClone)
  39.         NumColours = Handle->Screen->ViewPort.ColorMap->Count;
  40.     else
  41.     {
  42.         NumColours = Extra->TotalPens;
  43.  
  44.         DisplayID &= ~(HAM | EXTRA_HALFBRITE);
  45.     }
  46.  
  47.     Height += Handle->Screen->BarHeight + 1;
  48.  
  49.     if(Width < Extra->MinWidth)
  50.         Width = Extra->MinWidth;
  51.  
  52.     if(Height < Extra->MinHeight)
  53.         Height = Extra->MinHeight;
  54.  
  55.     if(Handle->SimpleClone)
  56.         Pens = &EndPen;
  57.     else
  58.     {
  59.         if(V39)
  60.         {
  61.             AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours;
  62.  
  63.             if(!(ColourRecord = (struct ColourRecord *)LTP_Alloc(Handle,AllocationSize)))
  64.             {
  65.                 DB(kprintf("no colours\n"));
  66.  
  67.                 return;
  68.             }
  69.             else
  70.             {
  71.                 ColourRecord->NumColours = NumColours;
  72.  
  73.                 if(Handle->ExactClone)
  74.                     GetRGB32(Handle->Screen->ViewPort.ColorMap,0,NumColours,(ULONG *)ColourRecord->Triplets);
  75.                 else
  76.                 {
  77.                     for(i = 0 ; i < NumColours ; i++)
  78.                         GetRGB32(Handle->Screen->ViewPort.ColorMap,Extra->Pens[i],1,(ULONG *)&ColourRecord->Triplets[i]);
  79.                 }
  80.             }
  81.         }
  82.         else
  83.         {
  84.             AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1);
  85.  
  86.             if(!(ColourSpec = (struct ColorSpec *)LTP_Alloc(Handle,AllocationSize)))
  87.             {
  88.                 DB(kprintf("no colours either\n"));
  89.  
  90.                 return;
  91.             }
  92.             else
  93.             {
  94.                 LONG RGB,Which;
  95.  
  96.                 for(i = 0 ; i < NumColours ; i++)
  97.                 {
  98.                     if(Handle->ExactClone)
  99.                         Which = i;
  100.                     else
  101.                         Which = Extra->Pens[i];
  102.  
  103.                     RGB = GetRGB4(Handle->Screen->ViewPort.ColorMap,Which);
  104.  
  105.                     ColourSpec[i].ColorIndex    = i;
  106.                     ColourSpec[i].Red            = (RGB >> 8) & 0xF;
  107.                     ColourSpec[i].Green            = (RGB >> 4) & 0xF;
  108.                     ColourSpec[i].Blue            = (RGB       ) & 0xF;
  109.                 }
  110.  
  111.                 ColourSpec[i].ColorIndex = -1;
  112.             }
  113.         }
  114.  
  115.         if(Handle->ExactClone)
  116.         {
  117.             for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  118.                 Pens[i] = Extra->Pens[i];
  119.         }
  120.         else
  121.         {
  122.             for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  123.             {
  124.                 for(j = 0 ; j < NumColours ; j++)
  125.                 {
  126.                     if(Extra->Pens[j] == Handle->DrawInfo->dri_Pens[i])
  127.                     {
  128.                         Pens[i] = j;
  129.  
  130.                         break;
  131.                     }
  132.                 }
  133.             }
  134.         }
  135.  
  136.         Pens[i] = (UWORD)~0;
  137.     }
  138.  
  139.     DB(kprintf("Calling openscreen\n"));
  140.  
  141.     if(Screen = OpenScreenTags(NULL,
  142.         SA_Width,        Width,
  143.         SA_Height,        Height,
  144.         SA_Overscan,    OSCAN_TEXT,
  145.         SA_AutoScroll,    TRUE,
  146.         SA_DisplayID,    DisplayID,
  147.         SA_Behind,        TRUE,
  148.         SA_Depth,        Handle->SimpleClone ? 2 : Extra->Depth,
  149.         SA_Colors,        ColourSpec,
  150.         SA_Colors32,    ColourRecord,
  151.         SA_Pens,        Pens,
  152.         SA_Font,        Handle->TextAttr,
  153.         SA_Title,        Handle->CloneScreenTitle ? Handle->CloneScreenTitle : Handle->Screen->DefaultTitle,
  154.         SA_SharePens,    TRUE,
  155.         SA_Interleaved,    TRUE,
  156.  
  157.         Handle->SimpleClone ? TAG_IGNORE : SA_BackFill,        &Handle->BackfillHook,
  158.         Handle->SimpleClone ? TAG_IGNORE : SA_BlockPen,        Pens[SHADOWPEN],
  159.         Handle->SimpleClone ? TAG_IGNORE : SA_DetailPen,    Pens[BACKGROUNDPEN],
  160.     TAG_DONE))
  161.     {
  162.         struct DrawInfo *DrawInfo;
  163.  
  164.         DB(kprintf("getting drawinfo\n"));
  165.  
  166.         if(DrawInfo = GetScreenDrawInfo(Screen))
  167.         {
  168.             APTR VisualInfo;
  169.  
  170.             DB(kprintf("getting visualinfo\n"));
  171.  
  172.             if(VisualInfo = GetVisualInfoA(Screen,NULL))
  173.             {
  174.                 UnlockPubScreen(NULL,Handle->PubScreen);
  175.  
  176.                 FreeScreenDrawInfo(Handle->Screen,Handle->DrawInfo);
  177.  
  178.                 FreeVisualInfo(Handle->VisualInfo);
  179.  
  180.                 Pens = DrawInfo->dri_Pens;
  181.  
  182.                 Handle->PubScreen        = NULL;
  183.                 Handle->Screen            = Screen;
  184.                 Handle->DrawInfo        = DrawInfo;
  185.                 Handle->VisualInfo        = VisualInfo;
  186.                 Handle->TextPen            = Pens[TEXTPEN];
  187.                 Handle->BackgroundPen    = Pens[BACKGROUNDPEN];
  188.                 Handle->ShinePen        = Pens[SHINEPEN];
  189.                 Handle->ShadowPen        = Pens[SHADOWPEN];
  190.                 Handle->AspectX            = DrawInfo->dri_Resolution.X;
  191.                 Handle->AspectY            = DrawInfo->dri_Resolution.Y;
  192.  
  193.                 if(Handle->SimpleClone)
  194.                     Handle->MaxPen = 0;
  195.                 else
  196.                     Handle->MaxPen = Extra->TotalPens - 1;
  197.  
  198.                 Extra->Screen = Screen;
  199.  
  200.                 LTP_Free(Handle,ColourRecord,AllocationSize);
  201.                 LTP_Free(Handle,ColourSpec,AllocationSize);
  202.  
  203.                 DB(kprintf("fertig\n"));
  204.  
  205.                 return;
  206.             }
  207.  
  208.             FreeScreenDrawInfo(Screen,DrawInfo);
  209.         }
  210.  
  211.         CloseScreen(Screen);
  212.     }
  213.  
  214.     LTP_Free(Handle,ColourRecord,AllocationSize);
  215.     LTP_Free(Handle,ColourSpec,AllocationSize);
  216.  
  217.     Handle->Failed = TRUE;
  218.  
  219.     DB(kprintf("fehlschlag\n"));
  220. }
  221.  
  222. BOOL
  223. LTP_PrepareCloning(struct LayoutHandle *Handle)
  224. {
  225.     DB(kprintf("prepare cloning\n"));
  226.  
  227.     if(Handle->CloneExtra)
  228.         return(TRUE);
  229.     else
  230.     {
  231.         struct DimensionInfo DimensionInfo;
  232.  
  233.         DB(kprintf("getting dimensions\n"));
  234.  
  235.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle->Screen->ViewPort)))
  236.         {
  237.             LONG AllocationSize;
  238.  
  239.             DB(kprintf("getting cloneextra\n"));
  240.  
  241.             if(Handle->CloneExtra = (struct CloneExtra *)LTP_Alloc(Handle,AllocationSize = sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle->DrawInfo->dri_NumPens + sizeof(UWORD)))
  242.             {
  243.                 LONG     i,j,TotalPens = 0;
  244.                 LONG    *Pens;
  245.                 BOOL     NotFound;
  246.  
  247.                 Handle->CloneExtra->Pens            = (LONG *)(Handle->CloneExtra + 1);
  248.                 Handle->CloneExtra->ScreenPens        = (UWORD *)(&Handle->CloneExtra->Pens[Handle->DrawInfo->dri_NumPens]);
  249.                 Handle->CloneExtra->MinWidth        = DimensionInfo.MinRasterWidth;
  250.                 Handle->CloneExtra->MinHeight        = DimensionInfo.MinRasterHeight;
  251.                 Handle->CloneExtra->MaxWidth        = DimensionInfo.MaxRasterWidth;
  252.                 Handle->CloneExtra->MaxHeight        = DimensionInfo.MaxRasterHeight;
  253.  
  254.                 Handle->CloneExtra->Bounds.Left        = 0;
  255.                 Handle->CloneExtra->Bounds.Top        = 0;
  256.                 Handle->CloneExtra->Bounds.Width    = DimensionInfo.MaxRasterWidth;
  257.                 Handle->CloneExtra->Bounds.Height    = DimensionInfo.MaxRasterHeight;
  258.  
  259.                 Pens = Handle->CloneExtra->Pens;
  260.  
  261.                 if(Handle->ExactClone)
  262.                 {
  263.                     for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  264.                         Pens[i] = Handle->DrawInfo->dri_Pens[i];
  265.  
  266.                     TotalPens = Handle->DrawInfo->dri_NumPens;
  267.  
  268.                     Handle->CloneExtra->Depth = Handle->DrawInfo->dri_Depth;
  269.                 }
  270.                 else
  271.                 {
  272.                     for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  273.                     {
  274.                         for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
  275.                         {
  276.                             if(Pens[j] == Handle->DrawInfo->dri_Pens[i])
  277.                                 NotFound = FALSE;
  278.                         }
  279.  
  280.                         if(NotFound)
  281.                             Pens[TotalPens++] = Handle->DrawInfo->dri_Pens[i];
  282.                     }
  283.  
  284.                     for(i = 0 ; i < DimensionInfo.MaxDepth ; i++)
  285.                     {
  286.                         if(TotalPens <= (1L << i))
  287.                         {
  288.                             Handle->CloneExtra->Depth = i;
  289.  
  290.                             break;
  291.                         }
  292.                     }
  293.                 }
  294.  
  295.                 DB(kprintf("totalpens=%ld depth=%ld\n",TotalPens,Handle->CloneExtra->Depth));
  296.  
  297.                 if((Handle->CloneExtra->TotalPens = TotalPens) && Handle->CloneExtra->Depth)
  298.                 {
  299.                     DB(kprintf("setting up glyphs\n"));
  300.  
  301.                     if(LTP_GlyphSetup(Handle,Handle->InitialTextAttr))
  302.                     {
  303.                         Handle->Failed = Handle->Rescaled = FALSE;
  304.  
  305.                         LTP_ResetGroups(Handle->TopGroup);
  306.  
  307.                         DB(kprintf("fertig\n\n"));
  308.  
  309.                         return(TRUE);
  310.                     }
  311.                 }
  312.                 else
  313.                 {
  314.                     LTP_Free(Handle,Handle->CloneExtra,AllocationSize);
  315.  
  316.                     Handle->CloneExtra = NULL;
  317.                 }
  318.             }
  319.         }
  320.     }
  321.  
  322.     DB(kprintf("fehlschlag\n\n"));
  323.  
  324.     return(FALSE);
  325. }
  326.  
  327. #endif    /* DO_CLONING */
  328.